package com.ruoyi.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.LogisticDetailHistory;
import com.ruoyi.order.service.ILogisticDetailHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 历史物流信息管理Controller
 * 
 * @author lzp
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/system/history")
public class LogisticDetailHistoryController extends BaseController
{
    @Autowired
    private ILogisticDetailHistoryService logisticDetailHistoryService;

    /**
     * 查询历史物流信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(LogisticDetailHistory logisticDetailHistory)
    {
        startPage();
        List<LogisticDetailHistory> list = logisticDetailHistoryService.selectLogisticDetailHistoryList(logisticDetailHistory);
        return getDataTable(list);
    }

    /**
     * 导出历史物流信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:history:export')")
    @Log(title = "历史物流信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LogisticDetailHistory logisticDetailHistory)
    {
        List<LogisticDetailHistory> list = logisticDetailHistoryService.selectLogisticDetailHistoryList(logisticDetailHistory);
        ExcelUtil<LogisticDetailHistory> util = new ExcelUtil<LogisticDetailHistory>(LogisticDetailHistory.class);
        util.exportExcel(response, list, "历史物流信息管理数据");
    }

    /**
     * 获取历史物流信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:history:query')")
    @GetMapping(value = "/{logisticId}")
    public AjaxResult getInfo(@PathVariable("logisticId") Long logisticId)
    {
        return success(logisticDetailHistoryService.selectLogisticDetailHistoryByLogisticId(logisticId));
    }

    @GetMapping(value = "/delivery/{deliveryOrderNo}")
    public AjaxResult getDelivery(@PathVariable("deliveryOrderNo") String deliveryOrderNo)
    {
        List<LogisticDetailHistory> list = logisticDetailHistoryService.selectLogisticDetailHistoryByDeliveryOrderNo(deliveryOrderNo);
        return success(list);
    }


    /**
     * 新增历史物流信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:history:add')")
    @Log(title = "历史物流信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LogisticDetailHistory logisticDetailHistory)
    {
        return toAjax(logisticDetailHistoryService.insertLogisticDetailHistory(logisticDetailHistory));
    }

    /**
     * 修改历史物流信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:history:edit')")
    @Log(title = "历史物流信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LogisticDetailHistory logisticDetailHistory)
    {
        return toAjax(logisticDetailHistoryService.updateLogisticDetailHistory(logisticDetailHistory));
    }

    /**
     * 删除历史物流信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:history:remove')")
    @Log(title = "历史物流信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logisticIds}")
    public AjaxResult remove(@PathVariable Long[] logisticIds)
    {
        return toAjax(logisticDetailHistoryService.deleteLogisticDetailHistoryByLogisticIds(logisticIds));
    }
}
